<template>
	<view style="height: 100%;">
		<u-navbar :title="title" autoBack placeholder :border="false"></u-navbar>
		<view class="login-box">
			<view class="login-box-title1">欢迎使用 花儿朵朵</view>
			<view class="login-box-title2">授权微信头像、昵称</view>
			<view class="login-box-logo">
				<view class="login-box-logo-size">
					<u--image :showLoading="true" src="https://zhengxin-pub.cdn.bcebos.com/logopic/6d857a79d0f2d08b2dbf037120add682_fullsize.jpg?x-bce-process=image/resize,m_lfit,w_200" :fade="true"
						duration="450" shape="circle" width="140rpx" height="140rpx"></u--image>
				</view>
			</view>
			<view class="login-box-title3">为提供优质服务，需要获取您的一下信息:</view>
			<view class="login-box-title4">您的公开信息(头像、昵称等)</view>
			<u-button @click="getUserProfile" :color="appColor" text="授权进入" shape="circle"/>
			<!-- <u-button v-else open-type="getUserInfo" @getuserinfo="getUserInfo" :color="appColor" text="授权进入" shape="circle"/> -->
		</view>
	</view>
</template>

<script>
	import {
		getAuth
	} from '@/api/home.js';
	import {mapActions} from 'vuex';
	export default {
		data() {
			return {
				title: '',
			}
		},
		computed: {
			appColor() {
				return this.appPrimaryColor
			},
			scrollViewHeight() {
				return this.scrollHeight - 44 + 'px';
			}
		},
		methods: {
			...mapActions(['setRegisterDetail']),
			// 新版本
			getUserProfile() {
				const that = this;
				wx.getUserProfile({
					desc: '完善个人资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						const {encryptedData, iv, signature, rawData} = res;
						uni.login({
							success(e) {
								const {code} = e;
								that.$cuLoading('授权中...').then(() => {
									getAuth({encryptedData, iv, signature, rawData, code}).then(res => {
										const {code, result, success} = res;
										if(code === 200 && success) {
											that.setRegisterDetail({
												registerDetail: result
											});
											uni.redirectTo({
												url: '/pageDiamond1/login/getPhone'
											})
										} else {
											uni.hideLoading();
											that.$cuTip('授权失败, 请重新授权')
										}
									}).catch(() => {
										uni.hideLoading();
									})
								})
							}
						})
					}
				})
			}
		},
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>

<style lang="scss" scoped>
	.login-box {
		padding: 32rpx;

		.login-box-title1 {
			padding: 32rpx 0;
			font-size: 44rpx;
			color: #000;
		}

		.login-box-title2 {
			font-size: 34rpx;
			color: #666;
		}

		.login-box-logo {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 96rpx 0;

			.login-box-logo-size {
				width: 140rpx;
				height: 140rpx;
			}
		}

		.login-box-title3 {
			font-size: 28rpx;
			color: #000;
			padding-bottom: 16rpx;
		}

		.login-box-title4 {
			font-size: 24rpx;
			color: #333;
			padding-bottom: 44rpx;
		}
	}
</style>
